﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ShopMS.Data;
using System.Data;

namespace ShopMS.Shell
{
    /// <summary>
    /// winLogin.xaml 的交互逻辑
    /// </summary>
    public partial class winLogin : Window
    {
        public winLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            DataAccess access = new DataAccess();

            if (txtUserId.Text.Trim() == string.Empty)
            {
                MessageBox.Show(this, "请输入用户ID", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtUserId.Focus();
                return;
            }
            
            DataTable dt = access.getDataTable(string.Format("select * from userinfo where {0}='{1}' AND {2}='{3}'",ShopMS.Common.UserInfo.userId_FieldName,txtUserId.Text.Trim(),ShopMS.Common.UserInfo.password_FieldName,txtPassword.Text.Trim() ));
            if (dt!=null && dt.Rows.Count>0) {
                MessageBox.Show("登录成功！");
                ShopMS.Common.UserInfo.userId = dt.Rows[0][ShopMS.Common.UserInfo.userId_FieldName].ToString();
                ShopMS.Common.UserInfo.userName = dt.Rows[0][ShopMS.Common.UserInfo.userName_FieldName].ToString();
                this.DialogResult = true;
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
